package com.magiccompass.alipay.barcode.zdummy;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value="/dummy")
public class DummyController {
	@Resource(name="dummyDao")
	private DummyDAO dummyDao;
	 
	@RequestMapping(method = RequestMethod.GET)
    public ModelAndView home() {
        List<DummyData> listUsers = dummyDao.list();
        ModelAndView model = new ModelAndView("dummy/list");
        model.addObject("userList", listUsers);
        return model;
    }
	
	@RequestMapping(value="/addInput")
    public String addInput(@ModelAttribute("dummyData") DummyData user,Model model) {
        return "dummy/addInput";
    }
	
	@RequestMapping(value="/add")
    public String add(@ModelAttribute("dummyData") DummyData dummyData,Model model) {
		try {
			dummyDao.addDummyData(dummyData);
			model.addAttribute("message", "success");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			model.addAttribute("message", "failed");
		}
        return "dummy/result";
    }
}
